package mule;

import java.util.Random;

import javax.swing.JOptionPane;

public class RandomEvent {
	Random rand;
	Player player;

	public RandomEvent(Player player) {
		this.player = player;
		rand = new Random();
	}

	public int getRandomEvent() {

		int multiplyFactor = 0;
		if (Game.roundNumber == 1 || Game.roundNumber == 2
				|| Game.roundNumber == 3)
			multiplyFactor = 25;
		else if (Game.roundNumber == 4 || Game.roundNumber == 5
				|| Game.roundNumber == 6 || Game.roundNumber == 7)
			multiplyFactor = 50;
		else if (Game.roundNumber == 8 || Game.roundNumber == 9
				|| Game.roundNumber == 10 || Game.roundNumber == 11)
			multiplyFactor = 75;
		else if (Game.roundNumber == 12)
			multiplyFactor = 100;

		if (player.equals(Game.playerArray[0])) {
			int random = rand.nextInt(4) + 1;
			if (random == 1) {
				JOptionPane
						.showMessageDialog(
								null,
								"YOU JUST RECEIVED A PACKAGE FROM"
										+ "THE GT ALUMNI CONTAINING 3 FOOD AND 2 ENERGY UNITS.");
				player.setFood(player.getFood() + 3);
				player.setEnergy(player.getEnergy() + 2);
			} else if (random == 2) {
				JOptionPane.showMessageDialog(null,
						"A WANDERING TECH STUDENT REPAID YOUR HOSPITALITY "
								+ "BY LEAVING TWO BARS OF ORE.");
				player.setOre(player.getOre() + 2);
			} else if (random == 3) {
				JOptionPane.showMessageDialog(null,
						"THE MUSEUM BOUGHT YOUR ANTIQUE PERSONAL COMPUTER FOR $"
								+ 8 * multiplyFactor + ".");
				player.setMoney(player.getMoney() + 8 * multiplyFactor);
			} else if (random == 4) {
				JOptionPane.showMessageDialog(null,
						"YOU FOUND A DEAD MOOSE RAT AND SOLD THE HIDE FOR $"
								+ 2 * multiplyFactor + ".");
				player.setMoney(player.getMoney() + 2 * multiplyFactor);
			}
			return random;
		} else {
			int random = rand.nextInt(7) + 1;
			if (random == 1) {
				JOptionPane
						.showMessageDialog(
								null,
								"YOU JUST RECEIVED A PACKAGE FROM"
										+ "THE GT ALUMNI CONTAINING 3 FOOD AND 2 ENERGY UNITS.");
				player.setFood(player.getFood() + 3);
				player.setEnergy(player.getEnergy() + 2);
			} else if (random == 2) {
				JOptionPane.showMessageDialog(null,
						"A WANDERING TECH STUDENT REPAID YOUR HOSPITALITY "
								+ "BY LEAVING TWO BARS OF ORE.");
				player.setOre(player.getOre() + 2);
			} else if (random == 3) {
				JOptionPane.showMessageDialog(null,
						"THE MUSEUM BOUGHT YOUR ANTIQUE PERSONAL COMPUTER FOR $"
								+ 8 * multiplyFactor + ".");
				player.setMoney(player.getMoney() + 8 * multiplyFactor);
			} else if (random == 4) {
				JOptionPane.showMessageDialog(null,
						"YOU FOUND A DEAD MOOSE RAT AND SOLD THE HIDE FOR $"
								+ 2 * multiplyFactor + ".");
				player.setMoney(player.getMoney() + 2 * multiplyFactor);
			} else if (random == 5) {
				JOptionPane.showMessageDialog(null,
						"FLYING CAT-BUGS ATE THE ROOF OFF YOUR HOUSE. REPAIRS COST $"
								+ 4 * multiplyFactor + ".");
				player.setMoney(player.getMoney() - 4 * multiplyFactor);
				if (player.getMoney() < 0) {
					player.setMoney(0);
				}
			} else if (random == 6) {
				JOptionPane
						.showMessageDialog(
								null,
								"MISCHIEVOUS UGA STUDENTS BROKE INTO YOUR STORAGE SHED AND STOLE HALF YOUR FOOD.");
				player.setFood(player.getFood() / 2);
			} else if (random == 7) {
				JOptionPane.showMessageDialog(null,
						"YOUR SPACE GYPSY INLAWS MADE A MESS OF THE TOWN. IT COST YOU $"
								+ 6 * multiplyFactor + " TO CLEAN IT UP.");
				player.setMoney(player.getMoney() - 6 * multiplyFactor);
				if (player.getMoney() < 0) {
					player.setMoney(0);
				}
			}
			return random;
		}
	}
}
